package com.jsgt.greekfire.ui.mine.coindetail.recharge.rechargerecord.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.fhx.core.base.BaseAdapter
import com.fhx.core.base.BaseViewHolder
import com.fhx.core.utils.DateFormatUtil
import com.jsgt.greekfire.R
import com.jsgt.greekfire.bean.BillBean

/**
 * 充币/提现记录适配器
 * author fhx
 * create time 2020/5/10 21:05
 **/
class RecordAdapter : BaseAdapter<BillBean>() {

    var TYPE = 0//0.充币 1.提币

    inner class VH(itemView: View) : BaseViewHolder(itemView) {
        var sum_tv: TextView? = null
        var status_tv: TextView? = null
        var date_tv: TextView? = null
        var title_tv: TextView? = null

        init {
            sum_tv = itemView.findViewById(R.id.sum_tv)
            status_tv = itemView.findViewById(R.id.status_tv)
            date_tv = itemView.findViewById(R.id.date_tv)
            title_tv = itemView.findViewById(R.id.title_tv)
        }

        fun bindData(bean: BillBean) {
            when (bean.status) {
                1 -> status_tv!!.text = "已提交"
                2 -> status_tv!!.text = "已完成"
                3 -> status_tv!!.text = "已拒绝"
            }
            if (TYPE == 0) {
                title_tv?.text = "普通充币"
                sum_tv?.text = bean.assetAmt.toString()
                date_tv?.text = DateFormatUtil.formatNew(bean.createTime, "MM月dd日 HH:mm")
            } else {
                title_tv?.text = "普通提币"
                sum_tv?.text = bean.money.toString()
                date_tv?.text = DateFormatUtil.formatNew(bean.updatedAt, "MM月dd日 HH:mm")
            }
        }
    }

    override fun provideViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder? {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.item_record, parent, false)
        return VH(view)
    }

    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
        val viewHolder = holder as VH
        viewHolder.bindData(dataList()[position])
    }
}